package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.pojo.entity.PageBean;
import com.itheima.pojo.entity.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 修改
     * @param user
     * @return
     */
    @PutMapping
    public ResponseEntity<Void> updateUser(@RequestBody User user){
        userService.updateUser(user);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    /**
     * 分页查询
     * @param pageCondition 查询条件
     * @param pageNum 当前页码值
     * @param pageSize 页面大小
     * @return
     */
    @GetMapping("/page")
    public ResponseEntity<PageBean<User>> findPageUser(@RequestParam("pageCondition") String pageCondition,
                                                       @RequestParam("pageNum") Long pageNum,
                                                       @RequestParam("pageSize") Long pageSize){

        PageBean<User> userPageBean=userService.findPageUser(pageCondition,pageNum,pageSize);

        return ResponseEntity.ok(userPageBean);
    }
}
